package com.hui.service.impl;

import com.hui.dao.StudentDao;
import com.hui.entity.Student;
import com.hui.service.StudentService;
import com.hui.util.DaoFactory;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 李昭辉
 * @Date: 2021/06/19/16:00
 * @Description:
 */
public class StudentServiceImpl implements StudentService {
    private StudentDao studentDao = DaoFactory.getStudentDao();
    private static final int pageSize = 6;

    @Override
    public int getTotalPage() {
        int count = studentDao.getCount();
        int totalPage = count / pageSize;
        if (count % 6 != 0) {
            totalPage++;
        }
        return totalPage;
    }

    @Override
    public List<Student> getPageStudent(int page) {
        int start = (page - 1) * pageSize;
        return studentDao.getPageStudent(start, pageSize);
    }

    @Override
    public List<Student> getStudentById(int id) {
        return studentDao.getStudentById(id);
    }

    @Override
    public boolean updateStudent(Student student) {
        return studentDao.updateStudent(student);
    }

    @Override
    public boolean deleteStudentById(int id) {
        return studentDao.deleteStudentById(id);
    }

    @Override
    public boolean insertStudent(Student student) {
        return studentDao.insertStudent(student);
    }
}
